﻿@model Telerik.Web.Mvc.GridModel<MeasureDimensionModel>
@using Telerik.Web.Mvc.UI;
@using System.Linq;
@{
    ViewBag.Title = T("Admin.Configuration.Measures.Dimensions").Text;
}

<div class="section-header">
    <div class="title">
        @T("Admin.Configuration.Measures.Dimensions")
    </div>
</div>

<div class="alert alert-warning alert-dismissible">
	@T("Admin.Configuration.Measures.Dimensions.Description")
	<button type="button" class="close" data-dismiss="alert">&times;</button>
</div>

<div>
	@(Html.Telerik().Grid<MeasureDimensionModel>(Model.Data)
			.Name("measuredimension-grid")
			.DataKeys(x =>
			{
				x.Add(y => y.Id).RouteKey("Id");
			})
			.Columns(columns =>
			{
				columns.Bound(x => x.Name)
					.Width(200);
				columns.Bound(x => x.SystemKeyword)
					.Width(150);
				columns.Bound(x => x.Ratio)
					.Format("{0:0.00000000}")
					.Width(180);
				columns.Bound(x => x.DisplayOrder)
					.Centered()
					.Width(100);
				columns.Bound(x => x.IsPrimaryDimension)
					.Width(100)
					.Centered()
					.Template(item => @Html.SymbolForBool(item.IsPrimaryDimension))
					.ClientTemplate(@Html.SymbolForBool("IsPrimaryDimension"))
					.ReadOnly();
				columns.Command(commands => commands.Select().Text(T("Admin.Telerik.GridLocalization.Select").ToString()))
					.Title(T("Admin.Configuration.Measures.Dimensions.Fields.MarkAsPrimaryDimension").Text)
					.Width(100);
				columns.Command(commands =>
				{
					commands.Edit().Localize(T);
					commands.Delete().Localize(T);
				}).Width(180)
				.HtmlAttributes(new { align = "right", @class = "omega" }); ;

			})
			.ToolBar(x => x.Insert())
			.Editable(x =>
			{
				x.Mode(GridEditMode.InLine);
			})
			.DataBinding(dataBinding =>
			{
				dataBinding.Ajax().Select("Dimensions", "Measure")
					.Update("DimensionUpdate", "Measure")
					.Delete("DimensionDelete", "Measure")
					.Insert("DimensionAdd", "Measure");
			})
			.ClientEvents(x => x.OnError("grid_onError"))
			.EnableCustomBinding(true))

	<script type="text/javascript">
		function grid_onError(e) {
			alert(e.XMLHttpRequest.responseText);
			e.preventDefault();
		}
	</script>

</div>
    
